import {observable,action,computed} from 'mobx';
import {WeaLocaleProvider} from 'ecCom';
import { WeaTableNew } from "comsMobx";
import { message, Modal } from "antd";
import * as API from "../../apis/portrait/individualMain";
import * as Util from "../../util/Util";
import { i18n } from '../../public/i18n';
import * as _ from "lodash";

const getLabel = WeaLocaleProvider.getLabel;
const confirm = Modal.confirm;
const info = Modal.confirm;
const { TableStore } = WeaTableNew;


export default class IndividualMain {
    /********************* unobservable list *********************/
    topBtnAndMenu = ()=> {
      return {
        iconProps: {
          icon:  <i className="icon-coms02-Portrait-of-personnel"/>,
          color: "#893D86",
        },
        menus:[
          {
            key: "1",
            disabled: false,
            icon: <i className="icon-search"/>,
            onClick: this.loadTabData,
            content: i18n.button.refresh(),
          },
        ]
      }
    }

    tabConfig =  {
      mainTab: {
        tabs: [
          {
            title: i18n.label.personalHomePage(),
            viewcondition: "0",
          },
          {
            title:  i18n.label.annualInventory() ,
            viewcondition: "1",
          },
          {
            title:  i18n.label.executionEvaluation() ,
            viewcondition: "2",
          },
          {
            title:  i18n.label.riskManagement() ,
            viewcondition: "3",
          },
        ],
        keyParam: "viewcondition",
        defaultKey: "0",
      },
      // 左侧人员组织树Tab
      leftTreTab: {
        tabs: [
          {
            title: i18n.label.myAttention(),
            index: "1",
          },
          {
            title: i18n.label.personnelOrganization(),
            index: "2",
          },
        ],
        keyParam: "index",
        defaultKey: "1",
      }
    }

    execAssessConst = () => {
      return {
        goalOptions: [
          { key: "0", showname: i18n.label.all() },
          { key: "1", showname: i18n.label.monthly() },
          { key: "2", showname: i18n.label.quarter() },
          { key: "3", showname: i18n.label.year() },
          { key: "4", showname: i18n.label.in3Year() },
          { key: "5", showname: i18n.label.in5Year() }
        ]
      }
    }
    /********************* unobservable list *********************/
    @computed get isAttentionTab() {
      return this.activeTreTabKey === "1";
    }
    //************** observable ************************/
    
    @observable isLoading = false; // 页面初始化的loading状态：数据加载成功前后前使用

    @observable hasRight = true;

    @observable dialogProps = {
      workRecord: { //工作记录详情dialog
        visible: false,
        title: "",
        style: {
          width:700,
          height:460,
        },
      }
    }

    @observable noUserChecked = true;

    @observable loadings = {
      treDataLoading:false,//个人画像-组织关注树-加载状态
      userInfoLoading: false, //个人首页-基本信息及综合素质加载状态
      influenceLoading: false, //个人首页-影响力数据加载状态
      workRecordLoading: false, //个人首页-系统工作记录加载状态
      riskDataLoading:false, //风险管理-数据加载状态
    }

    @observable isCollapse  = false;// 默认未收缩

    @observable hrmid = null;

    @observable riskDateCond = 2;

    @observable personalIndexData = {  //个人首页数据
      basicInfo: { //个人基本信息
      },
      assessItems: [ //综合评价Item
        {
          id: 1,
          type: i18n.label.age(),
          icon: "icon-coms-operation",
        },
        {
          id: 2,
          type: i18n.label.education(),
          icon: "icon-coms02-Knowledge-tree",
        },
        {
          id: 3,
          type: i18n.label.experience(),
          icon: "icon-portal-official",
        },
      ],
      canEditAutograph: false,
      autograph: {
        id: null,
        content: i18n.label.plzInputSignature()
      },
      influenceData: [], //影响力数据
      individualInfoTag:[], //个人标签
      sysWorkRecords: [] //系统工作记录
    }
    
    @observable execAssesData = { //个人执行力评测页面数据
      goalSelectedOption: "1",//目标选择
      goalLoading:false,
      taskLoading: false, // 任务数据是否正在加载
      performanceLoading: false, // 绩效数据是否正在加载
      goalDatas: {
        data: [],
        finishrate: "0",
        passrate: "0"
      },
      taskDatas: {
          data: [],
          finishrate: "0",
          passrate: "0"
      },
      performanceDatas: {
          data: [],
          passrate: "0"
      }
    }

    @observable individualRiskData = []; // 风险管理Tab页数据

    @observable workRecordTable = new TableStore(); //个人首页-系统工作记录详情WeaTable

    @observable activeTabKey = "0"; //主页面Tab activityKey @see tabConfig
    @observable activeTreTabKey = "1";// 左侧人员组织树Tab activityKey @see tabConfig

    @observable title = this.getTitleByKeyStr(i18n.module.whosPortrait(),i18n.label.me()); //WeaTop及窗口标题 默认“我的画像”

    @observable allAttentions = []; // 我的关注人员数据
    @observable userRoot = undefined; //人员组织树搜索

    //************** observable ************************/

    @action("个人画像-通用-页面标题设置")
    setTopTitile = (newTitle) => {
      this.title = newTitle || this.getTitleByKeyStr(i18n.module.whosPortrait(),i18n.label.me());
      
    }

    @action checkRight = ()=>{
      let params = {
        type: "3",
        id:this.hrmid
      }
      return API.checkViewRight(params).then(
        action((res) => {
          if (res.status === "1") {
            this.hasRight = res.canView;
            this.hrmid = res.id;
            this.personalIndexData.basicInfo.name = res.name;
          }
          return res.canView;
        }),error=>{
          this.hasRight = false;
        }
      );
    }
    
    @action
    updateHrmId(v) {
    this.hrmid = v;
    }

    @action
    updateUserRoot(data) {
      this.userRoot = data;
    }

    @action("个人画像-通用-左右layout收缩回调")
    onMainCollapse = ()=>{
      this.isCollapse = !this.isCollapse;
    }

    @action("个人画像-通用-时间选择组件修改事件")
    setRiskDateCond = (v) => {
      this.riskDateCond = v || 2;
    }

    @action("个人画像-左侧关注组织树-Tab页切换事件")
    onTreTabChange = (v)=> {
      this.activeTreTabKey = v || "1";
      if("1" === v) {
        this.getMyAttentionList();
      }
    }

    @action("个人画像-顶部Tab页切换事件")
    onMainTabChange = (v) => {
      this.activeTabKey = v || "0";
      //  年度盘点单独刷下权限
      if("1" === this.activeTabKey) {
        this.checkRight();
      }
    }

    @action("个人画像-左侧关注组织树-人员点击事件") 
    onTreAttentionItemClick = (item) => {
      this.noUserChecked = false;
      let { id,name,post,avatar,dep} = item;
      if(_.isString(item.avatar)) {
        avatar = JSON.parse(item.avatar);
      }
      let title = this.getTitleByKeyStr(i18n.module.whosPortrait(),item.name);
      this.hrmid = item.id;
      this.setTopTitile(title);
      window.title = title;
      this.checkALStatus();
      // todo 更新当前Tab页的数据
      this.loadTabData();
      // 直接用组织树的人员信息代替人员基本信息 后面接口连通后取消
      let { basicInfo } = this.personalIndexData;
      this.personalIndexData.basicInfo = {
        ...basicInfo,
        id:id,
        name:name,
        post:post,
        avatar:avatar,
        dep:dep,
        totalScore:Util.getRandom(50,100,0)+"",
        percent:Util.getRandom(50,100,1)+"%"
      }
      this.personalIndexData.assessItems.map(v=>{
        if(v.id === 1) {
          v.scoreColor = "#A9CC5B";
          v.score = Util.getRandom(50,100,0)+""
        } else if (v.id === 2) {
          v.scoreColor = "#F3B163";
          v.score = Util.getRandom(50,100,0)+"";
        } else {
          v.scoreColor = "#79BDEE";
          v.score = Util.getRandom(50,100,0)+"";
        }
        return v;
      });
    }  

    onWeaOrgTreClick = (item)=> {
      this.noUserChecked = false;
      let { id,name,avatar} = item;
      if(_.isString(item.avatar)) {
        avatar = JSON.parse(item.avatar);
      }
      let title = this.getTitleByKeyStr(i18n.module.whosPortrait(),item.name);
      this.hrmid = item.id;
      this.setTopTitile(title);
      window.title = title;
       // todo 更新当前Tab页的数据
       this.loadTabData();
       // 直接用组织树的人员信息代替人员基本信息 后面接口连通后取消
       let { basicInfo } = this.personalIndexData;
       this.personalIndexData.basicInfo = {
         ...basicInfo,
         id:id,
         name:name,
         avatar:avatar,
         totalScore:Util.getRandom(50,100,0)+"",
         percent:Util.getRandom(50,100,1)+"%"
       }
       this.personalIndexData.assessItems.map(v=>{
        if(v.id === 1) {
          v.scoreColor = "#A9CC5B";
          v.score = Util.getRandom(50,100,0)+""
        } else if (v.id === 2) {
          v.scoreColor = "#F3B163";
          v.score = Util.getRandom(50,100,0)+"";
        } else {
          v.scoreColor = "#79BDEE";
          v.score = Util.getRandom(50,100,0)+"";
        }
        return v;
      });
    }

    @action("个人画像-通用-加载Tab页对应数据") 
    loadTabData = async () => {
      this.checkRight().then(v=>{
        if (this.hasRight) {
          switch (this.activeTabKey) {
            case "3":
              this.loadIndividualRiskData();
              break;
            case "0":
              this.getIndividualUserInfo();
              break;
            case "2":
              this.getExecAssessPageData();
              break;
            default:
                break;
          }
        }
      });
    }
    
    @action("个人首页-数据加载")
    getIndividualUserInfo = ()=> {
      //  个人标签
      this.getIndividualInfoTag(); 
      //  个人签名
      this.getIndividualAutograph();
      //  个人基本信息、综合素质评分
      this.getIndividualBasicInfo();
      //  个人影响力
      this.getInfluenceData();
      //  个人工作记录
      this.getSysWorkRecords();
    }
   
    @action("个人首页-个人标签-获取数据")
    getIndividualInfoTag = (params={})=> {
      if (!params.id) {
        params.hrmid = this.hrmid;
      }
      this.loadings.userInfoLoading = true;
      API.getIndividualInfoTag(params).then(
        action((res) => {
          if (res.status) {
            this.personalIndexData.individualInfoTag = res.datas;
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.loadings.userInfoLoading= false;
        })
      );
    }

    @action("个人首页-个人标签-新增标签")
    addIndividualInfoTag = (params={}) => {
      this.loadings.userInfoLoading = true;
      params.hrmid = this.hrmid;
      API.addIndividualInfoTag(params).then(
        action((res) => {
          if (res.status) {
            message.success(i18n.message.onSuccess());
            this.getIndividualInfoTag();
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.loadings.userInfoLoading = false;
        })
      );
    }
    
    @action("个人首页-个人标签-删除标签") 
    delIndividualInfoTag = (params={}) => {
      this.loadings.userInfoLoading = true;
      API.delIndividualInfoTag(params).then(
        action((res) => {
          if (res.status) {
            message.success(i18n.message.onSuccess());
            Util.removeAarry(this.personalIndexData.individualInfoTag,params);
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.loadings.userInfoLoading = false;
        })
      );
    }

    @action("个人首页-个性签名-获取数据") 
    getIndividualAutograph = (params={}) => {
      this.loadings.userInfoLoading = true;
      params.hrmid = this.hrmid;
      API.getIndividualAutograph(params).then(
        action((res) => {
          if (res.status) {
            // i18n.label.plzInputSignature()
            this.personalIndexData.autograph = {
              id: res.datas.id || null,
              content:res.datas.content
            };
            this.personalIndexData.canEditAutograph = res.canEdit;
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.loadings.userInfoLoading = false;
        })
      );
    }

    @action("个人首页-个性签名-设置签名") 
    setIndividualAutograph = (content) => {
      let params = {
        id: null,
        ...this.personalIndexData.autograph,
        content:content,
      }
      params.hrmid = this.hrmid;
      this.loadings.userInfoLoading = true;
      API.setIndividualAutograph(params).then(
        action((res) => {
          if (res.status) {
            message.success(i18n.message.signatureUpdated());
            this.personalIndexData.autograph ={
              content:content,
              id: res.id,
            };
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.loadings.userInfoLoading = false;
        })
      );
    }

    @action("个人首页-基础信息及综合评分-获取数据")
    getIndividualBasicInfo = (params={}) => {
      const data = {
        id:54,
        // name: "TEST",
        dep: "需求分析部",
        duties: "技术研发",
        subordinate: 1,
        superiorId: 7,
        superiorName: "李大钊",
        post: "UI设计师",
        seniority: "7年",
        avatar: {
          headformat: "1",
          isDefault: true,
          gender: "0",
          background: "#55B1F9",
          messagerurl: "",
          fontcolor: "#FFFFFF",
          defaultmessagerurl: "",
          shortname: "T",
          lastname: "TEST"
        },
        totalScore: "83.5",
        percent: "78.6%",
        ageScore:"80",
        educationScore:"75",
        experienceScore:"84",
        goalColor: this.getColorFromScore("83.5"),
        percentColor: this.getColorFromScore("30.4%"),
      }
      if(this.noUserChecked) {
        let { basicInfo } = this.personalIndexData;
        this.personalIndexData.basicInfo = {
          ...basicInfo,
          ...data
        };
        this.personalIndexData.assessItems.map(v=>{
          if(v.id === 1) {
            v.scoreColor = "#A9CC5B";
            v.score = data.ageScore
          } else if (v.id === 2) {
            v.scoreColor = "#F3B163";
            v.score = data.educationScore;
          } else {
            v.scoreColor = "#79BDEE";
            v.score = data.experienceScore;
          }
          return v;
        });
      }
    }
  
    @action("个人首页-个人影响力-获取影响力指标") 
    getInfluenceData = (params={}) => {
      params.hrmid = this.hrmid;
      this.loadings.influenceLoading = true;
      API.getInfluenceList(params).then(
        action((res) => {
          if (res.status==="1") {
            let { data, userid} = res
            let formatedDatas = []
            data.forEach(d => {
              formatedDatas.push({
                ...d,
                desc:"",
                htmlStr: "",
              })
          })
          this.hrmid = userid;
          this.handleInfluenceData(formatedDatas);
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.loadings.influenceLoading = false;
        })
      );
    }

    @action("个人首页-个人影响力-获取每一项影响力指标的具体数值")  
    handleInfluenceData = async (data) =>{
      let params2 = {
        hrmid: this.hrmid,
      }
      let newData = [];
      for(let v of data){
        if(!Util.isEmpty(v.interfaceinfo)) {
          await API.getInfluenceData(v.interfaceinfo,params2).then(action( res =>{
             if(res.status == "1") {
              v = {
                ...v,
                ...res.data
              }
            }
          }),error=>{
            //
          });
        }
        let  r = this.replaceStrByObjKey(v,v.tipsinfo)
        v = {
          ...v,
          ...r
        }
        newData.push(v);
    }
    this.personalIndexData.influenceData = newData;
    }
    
    @action("个人首页-系统工作记录-获取系统工作记录") 
    getSysWorkRecords = (params={}) => {
      params.hrmid = this.hrmid;
      this.loadings.workRecordLoading = true;
      API.getWorkRecordList(params).then(
        action((res) => {
          if (res.status) {
          let { datas, userid} = res
            let formatedDatas = []
            datas.forEach(d => {
              formatedDatas.push({
                ...d,
                name: getLabel(d.labelId, d.labelName),
                count:0,
                view: "",
              })
          })
          this.hrmid = userid;
          this.handleWorkRecord(formatedDatas);
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }     
          this.loadings.workRecordLoading = false; 
        })
      );
    }

    @action("个人首页-系统工作记录-获取每一项工作记录的详情数据")  
    handleWorkRecord = async (data) => {
      let newData = [];
      let dateConds = Util.getDateRangeInDays(this.riskDateCond+1);
      let params2 = {
        hrmid: this.hrmid,
        startDate: dateConds[0],
        endDate: dateConds[1]
      }
      for( let v of data ) {
        if( v && !Util.isEmpty(v.interfaceInfo)) {
          await API.getWorkRecordDetail(v.interfaceInfo,params2).then(action( res =>{
             if(res.status == "1") {
              v.count = res.count;
              v.view = res.view;
            }
          }),error=>{
            //
          });
        }
        newData.push(v);
      }
      this.personalIndexData.sysWorkRecords = newData;
    }

    @action("个人首页-系统工作记录-工作记录详情WeaTable") 
    getWorkRecordTable = (view) => {
      let dateConds = Util.getDateRangeInDays(this.riskDateCond+1);
      let params={
        hrmid: this.hrmid,
        startDate: dateConds[0],
        endDate: dateConds[1]
      }
      API.getWorkRecordTable(view,params).then(
        action((res) => {
          if (res.api_status) {
            this.workRecordTable = new TableStore();
            this.workRecordTable.getDatas(res.datas);
          }
        })
      );
    }

    @action("个人首页-系统工作记录-展示工作记录详情Dialog")
    showWorkRecordDialog = (item)=>{
      if(!Util.isEmpty(item.view)){
        const { workRecord } = this.dialogProps;
        this.dialogProps.workRecord = {
          ...workRecord,
          title:item.name,
          visible:true,
        }
        this.getWorkRecordTable(item.view);
      }
    }

    @action("个人首页-系统工作记录-关闭工作记录详情Dialog") 
    closeWorkRecordDialog = () => {
      const { workRecord } = this.dialogProps;
        this.dialogProps.workRecord = {
          ...workRecord,
          title:"", //给个默认值
          visible:false
        }
        // 每次关闭 重刷下数据
        this.getSysWorkRecords();
    }

    // 个人画像-执行力评测页面
    @action("执行力评测-数据加载")
    getExecAssessPageData = () => {
      this.getGoalDatas();
      this.getTaskDatas();
      this.getPerformanceDatas();
    }

    @action("执行力评测-目标-获取数据") 
    getGoalDatas = (params={})=> {
      params.userid = this.hrmid;
      params.period = this.execAssesData.goalSelectedOption;
      params.operation = "1";
      this.execAssesData.goalLoading = true;
      API.getExecAssessData(params).then(
        action((res) => {
          if (res.status == 1) {
            this.execAssesData.goalDatas = {
                data: res.data.map(d => ({ ...d, percent: parseFloat(`${d.percent}` + "") })),
                finishrate: res.finishrate,
                passrate: res.passrate
            };
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.execAssesData.goalLoading = false;
        })
      );
    }

    @action("执行力评测-任务-获取数据")
    getTaskDatas = (params={})=> {
      params.userid = this.hrmid;
      params.operation = "2";
      this.execAssesData.taskLoading = true;
      API.getExecAssessData(params).then(
        action((res) => {
          if (res.status == 1) {
            this.execAssesData.taskDatas = {
              data: res.data.map(d => ({ ...d, percent: parseFloat(`${d.percent}` + "") })),
              finishrate: res.finishrate,
              passrate: res.passrate
            };
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.execAssesData.taskLoading = false;
        })
      );
    }

    @action("执行力评测-绩效-获取数据")  
    getPerformanceDatas = (params={})=> {
      params.userid = this.hrmid;
      params.operation = "3";
      this.execAssesData.performanceLoading = true;
      API.getExecAssessData(params).then(
        action((res) => {
          if (res.status == 1) {
            let { data, passrate } = res
            let formatedDatas = []
                    data.forEach(d => {
                        formatedDatas.push({
                            category: getLabel('522405', '平均绩效'),
                            xd: d.month,
                            yd: parseFloat(d.avgScore)
                        })
                        formatedDatas.push({
                            category: getLabel(28309, '我的绩效'),
                            xd: d.month,
                            yd: parseFloat(d.myScore)
                        })
                    })
            this.execAssesData.performanceDatas = {
                data: formatedDatas,
                passrate,
            };
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.execAssesData.performanceLoading = false;
        })
      );
    }

    @action("执行力评测-目标-时间下拉框改变监听事件")
    onGoalSelectedOptionChange = (value) => {
      this.goalSelectedOption = value;
      this.getGoalDatas();
    }

    // 风险管理页面 个人风险数据获取
    @action("风险管理-数据加载") 
    loadIndividualRiskData = (params ={}) => {
      params.hrmid = this.hrmid;
      params.dateCond = this.riskDateCond;
      let dateConds = Util.getDateRangeInDays(this.riskDateCond+1);
      params.startDate = dateConds[0];
      params.endDate = dateConds[1];
      this.loadings.riskDataLoading = true;
      API.getIndividualRiskData(params).then(
        action((res) => {
          if (res.status) {
            this.individualRiskData = res.datas;
          }else {
            message.error(res.msg || i18n.message.onFailed());
          }
          this.loadings.riskDataLoading = false;
        })
      );
    }

    @action("个人画像-关注组织树-加载我的关注列表数据")
    getMyAttentionList = (params={}) => {
      this.loadings.treDataLoading = true;
      params.type = 1;
      API.getMyAttentionList(params).then(
        action((res) => {
            if (res.api_status) {
              if (res.status) {
                  this.allAttentions = res.datas;
                  this.checkALStatus();
              } else {
                  message.error(res.msg || getLabel("519123", "获取接口数据失败"));
              }
            } else {
              message.error(res.msg || getLabel("508818", "接口调用失败！"));
            }
            this.loadings.treDataLoading = false;
        })
        );
    };

    @action checkALStatus = () => {
      if(this.hrmid != null ) {
        this.allAttentions = this.allAttentions.map((item) =>{
            if(item.id == this.hrmid) {
              if (item.dcheck) {
                this.hrmid = null;
                this.setTopTitile(this.getTitleByKeyStr(i18n.module.whosPortrait(),i18n.label.me()));
                this.noUserChecked = true;
              }
              item.dcheck = !item.dcheck;
            } else{
              item.dcheck = false;
            }
            return item;
        })
      }
    }

    @action("个人画像-关注组织树-新增我的关注")
    addMyAttention = (ids, names, datas) => {
      // 去重
      let newIds = datas.reduce((pre,cur)=>{
        let exist = this.includes(this.allAttentions,cur);
        if(!exist) {
          pre += cur.id+",";
        }
        return pre;
      },"");
      // 处理分隔符
      newIds = newIds.endsWith(",") ? newIds.slice(0,newIds.length-1) : newIds;
      // 如果不为空 才请求后台新增 为空代表当前添加人员已在关注列表中 无需处理。
      if (!Util.isEmpty(newIds)) {
        this.loadings.treDataLoading = true;
        let params = {
          toUserId: newIds,
          type:1
        };
        API.addMyAttention(params).then(
          action((res) => {
            if (res.api_status) {
              if (res.status) {
                message.success(i18n.message.onSuccess());
                this.getMyAttentionList();
              } else {
                message.error(res.msg || i18n.message.onFailed());
              }
            } else {
              message.error(res.msg || i18n.message.noResponse());
            }
            this.loadings.treDataLoading = false;
          })
        );
      }else {
        datas.length > 0 && message.warn(i18n.message.personAlreadyInFollowList())
      }
    };

    @action("个人画像-关注组织树-取消关注")
    cancleAttention = (index,userInfo) => {
        let content = i18n.confirm.unsubscribe() + userInfo.name + "?";
        this.confirmInfo({
          content,
          onOk: ()=> {
            this.loadings.treDataLoading = true;
            let params = {
              toUserId: userInfo.id,
              type:1
            }
            API.delMyAttention(params).then(
              action((res) => {
                  if (res.api_status) {
                  if (res.status) {
                      message.success(i18n.message.onSuccess());
                      this.allAttentions.splice(index, 1);
                  } else {
                    message.error(res.msg || i18n.message.onFailed());
                  }
                  } else {
                    message.error(res.msg || i18n.message.noResponse());
                  }
                  this.loadings.treDataLoading = false;
              })
              );
          }
        })
       
    };

    @action("个人画像-关注组织树-关注搜索框点击")
    onALSearchHandler = (v) => {
        //  空值搜索时 默认拉取所有数据
        let params = {
          searchStr: v|| "",
        }
        this.getMyAttentionList(params);
    };

    //  左侧人员组织关注树相关 结束
  
   /**
   * 判断当前关注数组是否已包含指定人员
   */
    includes = (array, item) => {
        for (const value of array) {
          if (value.id == item.id) {
              return true;
          }
        }
        return false;
    };

    confirmInfo = (props) => {
      confirm({ ...props,
        title: props.title || i18n.confirm.defaultTitle(),
        okText: i18n.button.ok(),
        cancelText: i18n.button.cancel()
      });
    }

    getColorFromScore = (score) => {
      score = parseInt(score);
      try {
        if (score < 60) {
          return "#DB8A2B";
        } else {
          let scoreB = score - 60;
          let p = score / 100;
          let pr = scoreB / 40;
          if (pr > 1) {
            pr = 1;
          }
          let r = parseInt(200 - pr * 200).toString(16);
          if (r.length < 2) {
            r = "0" + r;
          }
          let b = parseInt(p * 187).toString(16);
          if (b.length < 2) {
            b = "0" + b;
          }
          return "#" + r + "00" + b; //红绿蓝
        }
      } catch (e) {
        return "#F3B163";
      }
    }

    // 影响力指标描述替换
    replaceStrByObjKey = (obj,keyStr) =>{
      let htmlStr = keyStr;
      let desc = keyStr;
      Object.keys(obj|| {}).forEach((key)=>{
          let reg = `&${key}&`;
          htmlStr = htmlStr.replace(reg,`<strong>${obj[key]|| 0}</strong>`);
          desc = desc.replace(reg,obj[key]|| 0);
        });
      //  如果当前影响力指标没有接口或接口未正常响应 导致关键字无法正常替换 直接使用默认
      const reg = /&([\s\S]+?)&/g;
      while (reg.test(desc) || reg.test(htmlStr)) {
          desc = desc.replace(reg,(v,p)=>{
              if ("percent" === p) {
                  return '0%';
              } else {
                  return '0';
              }
          });
          htmlStr = htmlStr.replace(reg,(v,p)=>{
             if ("percent" === p) {
                 return '<strong>0%</strong>';
             } else {
                 return '<strong>0</strong>';
             }
          });
      }
      return {
        htmlStr,
        desc
      }
    }

    getTitleByKeyStr =(keyStr,value) => {
      return keyStr.replace("${name}",value);
    }


}